package com.avic.service.impl;

import com.avic.common.util.ex.BizErrorCode;
import com.avic.common.util.ex.BizException;
import com.avic.dal.condition.PageQueryMapVideoListCondition;
import com.avic.dal.model.MapVideo;
import com.avic.service.MapVideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author huangsheng on 2019/2/27
 */
@Service
@Slf4j
public class MapVideoServiceImpl extends AbstractServiceImpl implements MapVideoService {

    @Override
    public int createMapVideoRecord(MapVideo mapVideo) {
        try {
            mapVideoMapper.insert(mapVideo);
            return mapVideo.getId();
        } catch (Exception e) {
            log.error("创建视频记录时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR, "创建视频记录时发生错误");
        }
    }

    @Override
    public List<MapVideo> itemList(PageQueryMapVideoListCondition pageQueryMapVideoListCondition) {
        return mapVideoMapper.itemList(pageQueryMapVideoListCondition);
    }

    @Override
    public int itemTotalRecords(PageQueryMapVideoListCondition pageQueryMapVideoListCondition) {
        return mapVideoMapper.itemTotalRecords(pageQueryMapVideoListCondition);
    }

    @Override
    public void uploadUpdateVideo(MapVideo mapVideo) {
        try {
            mapVideoMapper.uploadUpdateVideo(mapVideo);
        } catch (Exception e) {
            log.error("更新视频记录时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR, "更新视频记录时发生错误");
        }
    }

    @Override
    public void uploadFailedUpdateVideo(MapVideo mapVideo) {
        try {
            mapVideoMapper.uploadFailedUpdateVideo(mapVideo);
        } catch (Exception e) {
            log.error("更新视频记录时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR, "更新视频记录时发生错误");
        }
    }

    @Override
    public MapVideo queryMapVideoRecord(int id) {
        return mapVideoMapper.queryMapVideoRecord(id);
    }
}
